﻿using Microsoft.Extensions.DependencyInjection;
using SBlogCore.Common.App.Manager;
using SBlogCore.EventBus.CrossProcessEventBus;
//using SBlogCore.EventBus.RabbitMQExtend;
using System.Reflection;

namespace SBlogCore.EventBus
{
    public static class SBlogCoreEventBusSetup
    {
        public static void AddSBlogCoreEventBusSetup(this IServiceCollection services, params Assembly[] assemblies)
        {
            //EventBus开启
            string enableEventBus = AppSetting.ReadAppSettings("EventBus:Enable");
            if (!string.IsNullOrEmpty(enableEventBus) && bool.Parse(enableEventBus))
            {
                string queueName = AppSetting.ReadAppSettings("EventBus:QueueName");
                string host = AppSetting.ReadAppSettings("EventBus:Host");
                int port = int.Parse(AppSetting.ReadAppSettings("EventBus:Port"));
                services.AddCrossEventBus(assemblies, options =>
                {
                    options.QueueName = queueName;
                    options.Host = host;
                    options.Port = port;
                });
            }
        }
    }
}
